# This example shows how ApMon can be used as a simple host sensor to monitor and send
# the desired parameters to the MonALISA service (configured in the given file/url)
use strict;
use warnings;

use Net::Domain;
use ApMon;

# redirect output
open STDOUT,">/dev/null";
open STDERR,">/dev/null";

my $userString="mvala";
my $superUserString="root";

my $apm = new ApMon("/etc/mlclient/monalisa.conf");

my $my_host = Net::Domain::hostfqdn();
#print "$my_host\n";

# the background data about the system will be sent with this cluster and node
$apm->setMonitorClusterNode("JKAF", $my_host);

# sleep forever
while(1){
  my $count = `pgrep proofserv | wc -l`;
  chomp($count);

  my $xproofdup = 0;
#   $xproofdup = 1 if (system("/cern/skaf/statusOfProcess.sh $superUserString xproofd") == 256);

  my $xrootdup = 0;
#   $xrootdup = 1 if (system("/cern/skaf/statusOfProcess.sh $userString xrootd > /dev/null") == 256);

  my $olbdup = 0;
#   $olbdup = 1 if (system("/cern/skaf/statusOfProcess.sh $userString cmsd > /dev/null") == 256);

#  print "Values: $count $xproofdup $xrootdup $olbdup\n";

  $apm->sendParameters("SKAF", $my_host, { "proofserv_count" => $count, "xproofd_up" => $xproofdup, "xrootd_up" => $xrootdup, "cmsd_up" => $olbdup});
  sleep 5;
}


